
import { Toast ,Dialog} from "vant"
import { Image as VanImage } from 'vant';
import AMap from "AMap";
import yz_uploader from "components/ui_components/yz_uploader";
export default {
  components: { VanImage,yz_uploader },
  data() {
    return {
      reason:"",
      picture1:"",
      picture2:"",
      strShow: false,
      streetShow_apply: false,
      text: '',
      apply_for_type: 1,//1-发布者申请、2-技能师傅申请、3-企业申请、4-技能师傅详情、5-区域代理-师傅详情、6-区域代理-添加师傅、7-发布者-重新申请

      corp_business_scope: "",
      locationTitle: "",
      radio: "",
      realname: "",
      mobile: "",
      age: "",
      shifu_video: [],
      corp_license: [],
      corp_image: [],
      id_card_front: [],
      id_card_reverse: [],//国徽面
      capability_certificate: [],//师傅技能证书
      health_certificate: [],//师傅健康证件
      shifu_image: [],//师傅个人照片
      native_place: "",
      nation: "",
      education: "",
      stature: "",
      weight: "",
      introduce: "",
      corp_address: "",
      corp_legal_person:"",
      corp_contact_way: "",
      corp_contact:"",
      corp_name: "",
      districtVal: [],

      corp_license_img:"",
      id_card_reverse_img:"",
      id_card_front_img:"",
      corp_image_imgs:[],


      point: {
        lng: 113.263630,
        lat: 23.160600
      },
      categoryShow: false,

      district: district, // 地址本地数据
      addressShow: false,
      streetShow: false,
      promulgator_form: {
        name: "",
        mobile: "",
        age: "",
        address: null,
        card_tail: "",
        card_front: ""
      },

      address_form: {
        province: "",
        city: "",
        district: "",
        street: "",
        address: ""
      },

      province_id: "",
      city_id: "",
      district_id: "",
      street_id: "",

      videoUrl: "",
      video: "",
      configInfo: {
        video_limit: 60
      },
      short_video: [],
      skill_certificate: [],
      mentor_form: {
        name: "",
        mobile: "",
        age: "",

      },

      apply_status: null,//审核状态

      show_skill_flag: false,
      member_realname: "",
      member_id: "",
      tips_list: [],
      show_serve_popup: false,//服务站弹窗
      columns: {},//服务站
      stree_columns: [],
      upload_flag: true,
      all_serve_columns: [],

      can_apply: 0,//999-可以申请
    };
  },
  activated() {
    if (!sessionStorage.getItem('any_tiem_form')) {
      this.init();
    }
    this.set_title_handle();
  },
  methods: {
    init() {
      this.reason = "";
      this.corp_image = []
      this.corp_image_imgs = [];
      this.corp_legal_person = "";
      this.corp_contact ="";
      this.corp_address="";
      this.strShow = false;
      this.streetShow_apply = false;
      this.can_apply = 0;
      this.video = "";
      this.upload_flag = true;
      this.columns = {};
      this.stree_columns = [];
      this.all_serve_columns = [];
      this.categoryShow = false;
      this.show_serve_popup = false;
      this.show_skill_flag = false;
      this.member_realname = "";
      this.tips_list = [];
      this.member_id = "";
      this.corp_business_scope = "";
      this.realname = "";
      this.locationTitle = "";
      this.mobile = "";
      this.age = "";
      this.videoUrl = '';
      this.id_card_reverse = [];
      this.short_video = [];
      this.corp_license = [];
      this.id_card_front = [];
      this.capability_certificate = [];
      this.shifu_video = [];
      this.shifu_image = [];
      this.health_certificate = [];
      this.addressName = "";
      this.radio = "";
      this.native_place = "";
      this.nation = "";
      this.education = "";
      this.stature = "";
      this.weight = "";
      this.introduce = "";

      this.address_form = {
        province: "",
        city: "",
        district: "",
        street: "",
        address: ""
      }
    },
    gotoRecord(){
      let name = "";
      if(this.apply_for_type==4 || this.apply_for_type == 2){
        name = 'skill_master';
      }else {
        name = 'promulgator';
      }
      if(this.apply_for_type == 5 || this.apply_for_type == 6){
        this.$router.push(this.fun.getUrl("anytimeArea"))
      }else{
        this.$router.push(this.fun.getUrl("anytimeMyRecord",{name}))
        }
    },
    async get_serve_address() {
      let { result, data } = await $http.get('plugin.be-within-call.frontend.area-manage.limit', {}, '');
      if (result) {
        let _arr = data.agent_address;
        this.all_serve_columns = _arr;
        this.formatdata(_arr);
      }
    },
    formatdata(data) {
      let obj1 = {}, obj2 = {}, obj3 = {};
      data.forEach(item => {

        if (!obj1[item.province_id]) {
          obj1[item.province_id] = item.province_name;
        }
        if (!obj2[item.city_id]) {
          obj2[item.city_id] = item.city_name;
        }
        if (!obj3[item.district_id]) {
          obj3[item.district_id] = item.district_name;
        }
      });
      this.columns = {
        province_list: obj1,
        city_list: obj2,
        county_list: obj3,
      }
    },
    focus() {
      this.show_skill_flag = true;
    },
    get_area_info() {
      this.member_realname = this.$route.params.uid;
      this.strShow = true;
      $http.get('plugin.be-within-call.frontend.area-manage.shifu-info', { uid: this.$route.params.uid }, '').then(res => {
        if (res.result) {
          let field = ['apply_status', 'realname', 'mobile', 'province_id', 'city_id', 'district_id', 'street_id'],
            detail_field = ['age', 'native_place', 'nation', 'education', 'stature', 'weight', 'introduce', ''];

          let data = res.data;
          this.reason = data.reason;

          field.forEach(item => {
            if (data[item]) {
              this[item] = data[item];
            }
          })
          detail_field.forEach(item => {
            if (data.detail_info[item]) {
              this[item] = data.detail_info[item];
            }
          })

          this.id_card_front_img = data.annex_file.id_card_front;
          this.id_card_reverse_img = data.annex_file.id_card_reverse;
          this.address_form.street = data.street_name;
          this.picture1 = data.annex_file.id_card_reverse_url;
          this.picture2 = data.annex_file.id_card_front_url;
          this.longitude= data.longitude;
          this.latitude= data.latitude;
          this.province_id= data.province_id;
          this.city_id= data.city_id;
          this.district_id= data.district_id;
          this.street_id= data.street_id;

          this.radio = data.detail_info && data.detail_info.sex == '男' ? '1' : '2';
          this.addressName = `${data.province_name} ${data.city_name} ${data.district_name}`;
          this.address_form.street = data.street_name;
          this.capability_certificate = [{ url: data.annex_file.capability_certificate_url, img: data.annex_file.capability_certificate_url }]
          this.id_card_front = [{ url: data.annex_file.id_card_front_url, img: data.annex_file.id_card_front }];
          this.id_card_reverse = [{ url: data.annex_file.id_card_reverse_url, img: data.annex_file.id_card_reverse }];
          this.health_certificate = [{ url: data.annex_file.health_certificate_url, img: data.annex_file.health_certificate }];
          this.shifu_image = [{ url: data.annex_file.shifu_image_url, img: data.annex_file.shifu_image }];
          this.videoUrl = data.annex_file.shifu_video_url;
          this.video = data.annex_file.shifu_video_url;
          this.shifu_video = [{ url: data.annex_file.shifu_video }]


          this.getAmap(data.city_name, data.longitude, data.latitude);

          let _stree = [];
          this.all_serve_columns.forEach(item => {
            if (item.district_id == data.district_id) {
              _stree.push(item.street_name);
            }
          })
          this.stree_columns = _stree;

          // if(data.apply_status==0 ){
          //   this.upload_flag = false;
          // }
          this.upload_flag = false;


        } else {
          this.$toast(res.msg);
        }
      })
    },
    getAmap(city, lng, lat) {
      AMap.plugin("AMap.Geocoder", () => {
        var geocoder = new AMap.Geocoder({ city });
        geocoder.getAddress([lng, lat], (status, result) => {
          if (status === 'complete' && result.info === 'OK') {
            // result为对应的地理位置详细信息
            this.locationTitle = result.regeocode.formattedAddress
          }
        })
      })
    },
    removeImg() {
      this.upload_flag = true;
      this.videoUrl = null;
      this.video = '';
    },
    choose_handle(data) {
      this.member_id = data.uid;
      this.member_realname = data.nickname;
      this.show_skill_flag = false;
      this.tips_list = [];
    },
    input_handle() {
      if (!this.show_skill_flag) {
        return false;
      }
      $http.get('plugin.be-within-call.frontend.area-manage.search-user', { kwd: this.member_realname }, '').then(res => {
        if (res.result) {
          this.tips_list = res.data;
          if (res.data && res.data.length !== 0) {
            this.show_skill_flag = true;
          }
        }
      })
    },
    republish(){

      Dialog.confirm({
        message: '请确认是否重复发布',
      })
        .then(() => {
          this.submit();
        })
        .catch(() => {
          // on cancel
        });
    },
    promulgator_detail(){ //发布者重新申请
      $http.get('plugin.be-within-call.frontend.role-apply.detail', { role:1, validate_page: 1 }, '').then(res=>{
        if (res.result) {
          let data = res.data;
          this.strShow = true;
          this.reason = data.reason;
          this.realname = data.realname;
          this.mobile = data.mobile;
          this.age = data.detail_info.age;
          this.addressName=`${data.province_name} ${data.city_name} ${data.district_name}`;
          this.address_form.street = data.street_name;
          this.id_card_front_img = data.annex_file.id_card_front;
          this.id_card_reverse_img = data.annex_file.id_card_reverse;
          this.province_id=data.province_id;
          this.city_id=data.city_id;
          this.district_id=data.district_id;
          this.street_id=data.street_id;
          this.$nextTick(()=>{
            this.picture1 = data.annex_file.id_card_front_url;
            this.picture2 = data.annex_file.id_card_reverse_url;
            this.id_card_front = [{ url: data.annex_file.id_card_front_url }];
            this.id_card_reverse = [{ url: data.annex_file.id_card_reverse_url }];
          })
        }else{
          this.$toast(res.msg);
        }
      })
    },
    detail(role) {
      $http.get('plugin.be-within-call.frontend.role-apply.detail', { role, validate_page: 1 }, '').then(res => {
        if (res.result) {
          if (this.apply_for_type == 1 || this.apply_for_type == 2 || this.apply_for_type == 3) {
            if (res.validate_page.is_auth == 0 && res.validate_page.real_name_auth_is_open && res.validate_page.real_name_auth_scene.indexOf("13") > -1) {
              this.$store.commit("setCallback", window.location.href);
              let MinUrl = this.fun.getSiteRoot() + "/addons/yun_shop/?menu#/personBank?from=bindRealName&i=" + this.fun.getKeyByI() + "&type=" + this.fun.getTyep() + "&mid=" + this.fun.getKeyByMid();
              window.location.href = MinUrl;
            }
          }
          let data = res.data;
          this.can_apply = data.can_apply;
          this.apply_status = data.apply_status;
          this.reason = data.reason;
          if ((data.apply_status == 0 || data.can_apply == 99)&&role!==2) {
            return;
          }
          this.realname = data.realname;
          this.radio = data.detail_info.sex == '男' ? '1' : '2';
          this.mobile = data.mobile;
          this.age = data.detail_info.age;
          this.addressName = `${data.province_name} ${data.city_name} ${data.district_name}`;
          this.address_form.street = data.street_name;
          this.native_place = data.detail_info.native_place;
          this.nation = data.detail_info.nation;
          this.education = data.detail_info.education;
          this.stature = data.detail_info.stature;
          this.weight = data.detail_info.weight;
          this.introduce = data.detail_info.introduce
          this.id_card_front = [{ url: data.annex_file.id_card_front_url }];
          this.id_card_reverse = [{ url: data.annex_file.id_card_reverse_url }];
          this.shifu_image = [{ url: data.annex_file.shifu_image_url,img:data.annex_file.shifu_image  }];
          this.videoUrl = data.annex_file.shifu_video_url;
          if(data.annex_file.capability_certificate){ //技能证书
            this.capability_certificate = [{ url: data.annex_file.capability_certificate_url ,img:data.annex_file.capability_certificate }]
          }
          if(data.annex_file.health_certificate){ //健康证件
            this.health_certificate = [{ url: data.annex_file.health_certificate_url,img:data.annex_file.health_certificate }];
          }
          this.id_card_front_img = data.annex_file.id_card_front;
          this.id_card_reverse_img = data.annex_file.id_card_reverse;
          this.strShow = true;
          this.address_form.street = data.street_name;
          this.picture1 = data.annex_file.id_card_reverse_url;
          this.picture2 = data.annex_file.id_card_front_url;
          this.longitude= data.longitude;
          this.latitude= data.latitude;
          this.radio = data.detail_info.sex == '男' ? '1' : '2';
          this.province_id= data.province_id;
          this.city_id= data.city_id;
          this.district_id= data.district_id;
          this.street_id= data.street_id;
          this.getAmap(data.city_name, data.longitude, data.latitude);
        } else {
          this.$toast(res.msg);
        }
      })
    },
    ready() {
      this.fun
        .getLocation()
        .then(res => {
          console.log(res, "res");
          this.point = res.point;
          this.locationTitle = res.title;
        })
        .catch(err => {
          console.log(err);
        });
    },
    onloadeddata(e) {
      if (this.apply_for_type == 4 || this.apply_for_type == 5 || !this.upload_flag) {
        return;
      }
      console.log("上传");
      let duration = e.target.duration;
      if (duration > 60) {
        Toast(`视频长度限制60秒`);
        this.videoUrl = null;
        return;
      }
      this.afterReadVideo();
    },
    beforeReadVideo(e) {
      //文件读取前的回调函数，返回 false 可终止文件读取，支持返回 Promise
      console.log("文件 读取前 的回调", e);
      return new Promise((resolve, reject) => {
        let endsName = !(e.name.endsWith(".mp4") || e.name.endsWith(".MP4") || e.name.endsWith(".mov") || e.name.endsWith(".MOV"));
        if (endsName) {
          this.$dialog.alert({ message: "请上传MP4或MOV格式视频" });
          reject();
        } else {
          this.realVideo = e;
          if (window.createObjectURL != undefined) {
            // basic
            this.videoUrl = window.createObjectURL(e); //类型1
          } else if (window.URL != undefined) {
            // mozilla(firefox)
            this.videoUrl = window.URL.createObjectURL(e); //类型2
          } else if (window.webkitURL != undefined) {
            // webkit or chrome
            this.videoUrl = window.webkitURL.createObjectURL(e); //类型3
          }

          if (this.fun.isIosOrAndroid() == "ios") {
            this.$nextTick(() => {
              setTimeout(() => {
                this.$refs.video.play();
              }, 10);
              this.$refs.video.pause();
            });
          }
          resolve(e);
        }
      });
    },
    stree_confirm(value) {
      let result = this.all_serve_columns.filter(item => {
        if (item.province_id == this.province_id && item.city_id == this.city_id && item.district_id == this.district_id) {
          return item;
        }
      })
      result.forEach(item => {
        if (item.street_name == value) {
          this.street_id = item.street_id;
        }
      })
      this.address_form.street = value;
      this.streetShow = false;
    },
    stree_cancel() {
      this.streetShow = false;
    },
    serve_confirm(columnsNum) {
      this.stree_columns = [];
      this.addressName = `${columnsNum[0].name} ${columnsNum[1].name} ${columnsNum[2].name}`;
      this.province_id = columnsNum[0].code;
      this.city_id = columnsNum[1].code;
      this.district_id = columnsNum[2].code;
      let _arr = this.all_serve_columns.filter(item => {
        if (item.province_id == columnsNum[0].code && item.city_id == columnsNum[1].code && item.district_id == columnsNum[2].code) {
          return item;
        }
      })
      _arr.forEach(item => {
        this.stree_columns.push(item.street_name);
      })
      this.show_serve_popup = false;
      this.streetShow = true;
      this.strShow = true;
    },
    serve_cancel() {
      this.show_serve_popup = false;
    },
    // 地址回调
    addressCallback(obj) {
      this.addressName = obj.itemName1 + " " + obj.itemName2 + " " + obj.itemName3;
      this.address_form.province = obj.itemName1;
      this.address_form.city = obj.itemName2;
      this.address_form.district = obj.itemName3;

      this.province_id = obj.itemValue1;
      this.city_id = obj.itemValue2;
      this.district_id = obj.itemValue3;
      console.log(obj);
      this.getStreet(obj.itemValue3);
    },
    // 获取街道
    getStreet(param) {
      this.district_id = param;
      $http
        .get("member.memberAddress.street", {
          district_id: param
        }, '加载中')
        .then(response => {
          if (response.result === 1 && !this.fun.isTextEmpty(response.data)) {
            if (!this.fun.isTextEmpty(response.data) && response.data.length > 0) {
              this.districtVal = response.data;
              this.strShow = true;
              console.log(this.districtVal, "districtVal");

            } else {
              this.strShow = false;
            }
          } else {
            this.strShow = false;
          }
        })
        .catch(error => {
          this.strShow = false;
          console.log(error);
        });
    },
    streetConfirm(item) {
      this.street_id = item.id;
      this.address_form.street = item.areaname;
      this.streetShow_apply = false;
    },
    validate() {
      let text = {}
      if (this.apply_for_type == 1) {
        text = {
          "id_card_front": "请上传身份证人像面",
          "id_card_reverse": "请上传身份证国徽面",
        }
        for (const key in text) {
          if (this[key] instanceof Array) {
            if (this[key].length == 0) {
              this.$toast(text[key]);
              return false;
            }
          } else if (typeof this[key] == 'string') {
            if (!this[key]) {
              this.$toast(text[key]);
              return false;
            }
          }
        }
        return true;
      } else if (this.apply_for_type == 2 || this.apply_for_type == 6) {
        text = {
          "id_card_front": "请上传身份证人像面",
          "id_card_reverse": "请上传身份证国徽面",
          "capability_certificate": "请上传技能证书",
          "shifu_image": "请上传个人照片",
          // "shifu_video": "请上传短视频",
          "realname": "请填写姓名",
          "mobile": "请填写手机号",
          "radio": "请选择性别",
          "addressName": "请选择所在区域",
          "locationTitle": "请选择地理位置"
        }
        for (const key in text) {
          if (this[key] instanceof Array) {
            if (this[key].length == 0) {
              this.$toast(text[key]);
              return false;
            }
          } else if (typeof this[key] == 'string') {
            if (!this[key]) {
              this.$toast(text[key]);
              return false;
            }
          }
        }
        if (!this.street_id) {
          this.$toast("请选择街道");
          return false;
        }
        return true;
      }

    },
    getParams() {

      let json = {};
      if (this.apply_for_type == 1 || this.apply_for_type == 7) {
        json = {
          identity: 1,
          realname: this.realname,
          mobile: this.mobile,
          detail_info: {
            age: this.age,
          },
          province_id: this.province_id,
          city_id: this.city_id,
          district_id: this.district_id,
          street_id: this.street_id,
          annex_file: {
            id_card_front: this.id_card_front_img,
            id_card_reverse: this.id_card_reverse_img
          }
        }
      } else if (this.apply_for_type == 2 || this.apply_for_type == 6) {
        json = {
          identity: 2,
          realname: this.realname,
          mobile: this.mobile,
          province_id: this.province_id,
          city_id: this.city_id,
          district_id: this.district_id,
          street_id: this.street_id,
          longitude: this.point.lng,
          latitude: this.point.lat,
          detail_info: {
            sex: this.radio == 1 ? '男' : '女'
          },
          annex_file: {
            id_card_front: this.id_card_front_img,
            id_card_reverse: this.id_card_reverse_img,
            shifu_image: this.shifu_image[0].img
          }

        }
        if (this.shifu_video && this.shifu_video.length !== 0) {
          json.annex_file.shifu_video = this.shifu_video[0].url
        }
        if(this.capability_certificate&& this.capability_certificate.length !== 0){
          json.annex_file.capability_certificate = this.capability_certificate[0].img
        }
        if (this.health_certificate && this.health_certificate.length !== 0) {
          json.annex_file.health_certificate = this.health_certificate[0].img;
        }
        let optional_data = ['age', 'native_place', 'nation', 'education', 'stature', 'weight', 'introduce'];
        for (const iterator of optional_data) {
          if (this[iterator]) {
            json.detail_info[iterator] = this[iterator]
          }
        }

      } else if (Number(this.apply_for_type) == 3) {
        json = {
          identity: 3,
          realname: this.realname,
          mobile: this.mobile,
          detail_info: {
            introduce:this.introduce,
            corp_address:this.corp_address,
            corp_contact:this.corp_contact,
            corp_business_scope:this.corp_business_scope,
            corp_legal_person:this.corp_legal_person,
          },
          annex_file: {
            corp_license:this.corp_license_img,
            id_card_reverse:this.id_card_reverse_img,
            id_card_front:this.id_card_front_img,
            corp_image:this.corp_image_imgs
          }
        }
      }
      return json;
    },
    submit(type='') {
      if(type == 'anew'){
        this.reason = "";
        return;
      }
      let json = this.getParams();
      if (!json) {
        return false;
      }
      let url = "plugin.be-within-call.frontend.role-apply.index";
      if (this.apply_for_type == 6) {
        url = 'plugin.be-within-call.frontend.area-manage.add-shi-fu';
        json.member_id = this.member_id;
        delete json.identity
      }
      $http.post(url, { data: json }, '').then(({ result, msg }) => {
        this.$toast(msg);
        if (result) {
          if (sessionStorage.getItem('any_tiem_form')) {
            sessionStorage.removeItem('any_tiem_form')
          }
          this.$router.replace(this.fun.getUrl("anytimeMy", { option: "wisdom" }));
        }
      })

    },
    async set_title_handle() {
      let role = null;
      let apply_for_type = this.$route.params.apply_for_type;
      this.apply_for_type = apply_for_type;
      if (apply_for_type == 1) {
        this.text = '发布者申请';
        this.fun.setWXTitle('发布者申请');
        role = 1;
      } else if (apply_for_type == 2 || apply_for_type == 6) {
        this.text = "技能师傅申请";
        this.fun.setWXTitle('技能师傅申请')
        if (!this.$route.params.uid) {
          if (localStorage.getItem('myLocation')) {
            let myLocation = JSON.parse(localStorage.getItem('myLocation'));
            this.point = myLocation.point;
            this.locationTitle = myLocation.address;
          } else {
            this.ready();
          }
        }
        if (apply_for_type == 6) {
          this.text = "添加技能师傅";
          this.fun.setWXTitle('添加技能师傅')
          await this.get_serve_address()
        }
        role = 2;
      } else if (apply_for_type == 3) {
        this.text = '企业申请';
        this.fun.setWXTitle('企业申请')
        role = 3;
      } else if (apply_for_type == 4) {
        this.text = '技能师傅主页';
        this.fun.setWXTitle('技能师傅主页')
        role = 2;
      } else if (apply_for_type == 5) {
        this.text = '技能师傅信息';
        this.fun.setWXTitle('技能师傅主页')
      } else if(apply_for_type == 7){ //发布者-重新申请
        this.text = '发布者申请';
        this.fun.setWXTitle('发布者申请');
        this.promulgator_detail();
      }
      if (apply_for_type == 1 || apply_for_type == 2 || apply_for_type == 3 || apply_for_type == 4 ) {
        this.detail(role);
      }
      if ((apply_for_type == 5 || apply_for_type == 6) && this.$route.params.uid) {
        this.member_id = this.$route.params.uid;
        // if (this.$route.params.uid) {
        //   this.upload_flag = false;
        // }
        this.get_area_info();
      }
    },
    go_to_loaction() {
      let field = ['realname', 'mobile', 'province_id', 'city_id', 'district_id', 'street_id', 'native_place', 'nation', 'education', 'weight', 'introduce', 'stature', 'addressName', 'radio'];
      let files = ['id_card_front', 'id_card_reverse', 'capability_certificate', 'health_certificate', 'shifu_image']
      let json = {
        longitude: this.point.lng,
        latitude: this.point.lat,
        street: this.address_form.street,
        shifu_video: [{ url: this.shifu_video[0] && this.shifu_video[0].url }]
      };
      files.forEach(item => {
        if (this[item] && this[item].length !== 0) {
          json[item] = [{ img: this[item][0].img, url: this[item][0].url }];
        }
      })
      field.forEach(item => {
        console.log(typeof this[item]);
        if (this[item]) {
          json[item] = this[item];
        }
      })
      sessionStorage.setItem('any_tiem_form', JSON.stringify(json));
      this.$store.commit("setReferer", window.location.href);
      this.$router.push(this.fun.getUrl("o2oLocation_loc", { fromHome: 1 }));
    },
    afterReadVideo(e) {
      Toast.loading({
        message: "上传中",
        forbidClick: true
      });
      let uploadAudio = this.fun.getRealUrl("upload.uploadPic", {});
      uploadAudio += "upload_type=video";
      let fd = new FormData();
      fd.append("file", this.realVideo); //进度百分比
      axios
        .post(uploadAudio, fd, {
          headers: { "Content-Type": "multipart/form-data" }
        })
        .then(response => {
          Toast.clear();
          if (response.data.result == 1) {
            console.log(response);
            this.shifu_video = [{ url: response.data.data.img }];
            this.video = response.data.data.img;
            Toast.success("上传成功");
          } else {
            this.videoUrl = null;
          }
        })
        .catch(error => {
          Toast.clear();
          this.videoUrl = null;
          console.log(error);
        });
    },
    afterReadCorpImage(e) {
      this.blobToBase64(e.file).then(result => {
        let fd = new FormData();
        fd.append("file", result);
        this.uploadFile(fd, 'corp_image');
      })
    },
    afterReadHealth(e) {
      this.blobToBase64(e.file).then(result => {
        let fd = new FormData();
        fd.append("file", result);
        this.uploadFile(fd, 'health_certificate');
      })
    },
    afterReadCorp(e) {
      this.blobToBase64(e.file).then(result => {
        let fd = new FormData();
        fd.append("file",result);
        this.uploadFile(fd, 'corp_license');
      })
    },
    afterReadPhoto(e) {
      this.blobToBase64(e.file).then(result => {
        let fd = new FormData();
        fd.append("file", result);
        this.uploadFile(fd, 'shifu_image');
      })
    },
    afterReadCardFront(e) {
      this.blobToBase64(e.file).then(result => {
        let fd = new FormData();
        fd.append("file", result);
        this.uploadFile(fd, 'id_card_front');
      })
    },
    afterReadCertificate(e) {
      this.blobToBase64(e.file).then(result => {
        let fd = new FormData();
        fd.append("file", result);
        this.uploadFile(fd, 'capability_certificate');
      })
    },
    afterReadCardTaill(e) {
      this.blobToBase64(e.file).then(result => {
        let fd = new FormData();
        fd.append("file", result);
        this.uploadFile(fd, 'id_card_reverse');
      })
    },
    input_reverse(imgVal){
      this.id_card_reverse_img = imgVal[0];
    },
    input_license(imgVal) {
      this.corp_license_img = imgVal[0];
    },
    input_front(imgVal) {
      this.id_card_front_img = imgVal[0];
    },
    async blobToBase64(blob) {
      const reader = await new FileReader() // 实例化一个reader文件
      await reader.readAsDataURL(blob) // 添加二进制文件
      return new Promise((resolve, reject) => {
        reader.onload = async (event) => {
          const base64 = await event.target.result // 获取到它的base64文件
          const scale = 0.70 // 设置缩放比例 （0-1）
          let file = await this.compressImg(base64, scale)
          resolve(file)
        }
      })
    },
    async compressImg(base64, scale) {
      console.log(`执行缩放程序，scale=${scale}`)
      // 处理缩放，转换格式
      // 下面的注释就不写了，就是new 一个图片，用canvas来压缩
      const img = new Image()
      img.src = base64
      return new Promise(function (resolve, reject) {
        img.onload = async function () {
          const canvas = document.createElement('canvas')
          const ctx = canvas.getContext('2d')
          canvas.setAttribute('width', this.width)
          canvas.setAttribute('height', this.height)
          ctx.fillStyle = "#ffffff";
          ctx.fillRect(0,0,canvas.width,canvas.height)
          // 在canvas绘制前填充白色背景  解决出现压缩png图片背景黑色问题
          ctx.clearRect(0, 0, canvas.width, canvas.height)
          ctx.drawImage(img, 0, 0, canvas.width, canvas.height)
          // 转成base64 文件
          base64 = canvas.toDataURL('image/jpeg', 0.3)
          const arr = base64.split(',')
          const mime = arr[0].match(/:(.*?);/)[1]
          const bytes = atob(arr[1])
          const bytesLength = bytes.length
          const u8arr = new Uint8Array(bytesLength)
          for (let i = 0; i < bytes.length; i++) {
            u8arr[i] = bytes.charCodeAt(i)
          }
          const file = await new File([u8arr], 'filename', { type: mime })
          resolve(file)
        }
      })
    },
    uploadFile(fd, field) {
      if (field !== 'corp_image') {
        this[field] = [{
          url: "",
          status: 'uploading',
          message: '上传中...',
        }]
      } else {
        Toast.loading({
          message: '上传中...',
          forbidClick: true,
        });
      }
      let uploadUrl = this.fun.getRealUrl("upload.uploadPic", {});
      axios
        .post(uploadUrl, fd, {
          headers: { "Content-Type": "multipart/form-data" }
        })
        .then(res => {
          let { data, result, msg } = res.data;
          this.$toast(msg);
          if (result) {
            if (field == 'corp_image') {
              if (this.corp_image && this.corp_image.length !== 0 && this.corp_image[0].img) {
                this.corp_image.splice(this.corp_image.length - 1, 1, { url: data.img_url, status: 'done', img: data.img })
              } else {
                this.corp_image = [{ url: data.img_url, status: 'done', img: data.img }];
              }
              this.corp_image_imgs.push(data.img);
            } else {
              if(Number(this.apply_for_type) == 3){
                this[`${field}_img`] = data.img;
              }
              this[field] = [{ url: data.img_url, status: 'done', img: data.img }];
            }
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
  }
};